<?php
class ArrayHelper{
	public static function getArrayIds($data = array()){
		if(!is_array($data)){
			return array('-1');
		}
		$rs = array('-1');
		foreach($data as $val){
			$rs[] = $val['id'];
		}
		return $rs;
	}
	public static function getStringIds($data = array()){
		if(!is_array($data)){
			return '-1';
		}
		$rs = '-1';
		foreach($data as $val){
			$rs.=','.$val['id'];
		}
		return $rs;
	}
	public static function getArrayIdsFromText($string = '', $separator=',', $strRemove = array()){
		$arr = explode($separator, $string);
		$rt = array();
		foreach($arr as $val){
			if(empty($val)) continue;
			$str = $val;
			foreach($strRemove as $r){
				$str = str_replace($r, '', $str);
			}
			$rt[] = $str;
		}
		return $rt;
	}
	public static function getStringIdsMultiLevel($data = array()){
		if(!is_array($data) || count($data)<=0 ){
			return '';
		}
		$str = $data['id'];
		if(isset($data['children'])){
			foreach($data['children'] as $val){
				$str.=','. self::getStringIdsMultiLevel($val, $val['id']);
			}
		}
		return $str;

	}
	public static function getStringOptionMultiLevel($data = array(), $cateId = 0, $currentId = -2 ){
		if(!is_array($data) || count($data)<=0 || intval($data['id'])==intval($currentId)){
			return '';
		}
		$str = '<option value="'.$data['id'].'" '.(intval($data['id'])==intval($cateId)?'selected':'').'>'.self::getStringHeadOptionLevel(intval($data['level'])).$data['name'].'</option>';
		if(isset($data['children'])){
			foreach($data['children'] as $val){
				$str.= self::getStringOptionMultiLevel($val, $cateId, $currentId);
			}
		}
		return $str;
	}
	/******************************************/
	public static function getStringHeadOptionLevel($level = 0, $strSepa = '.'){
		$str = '';
		for($i=0; $i<$level; $i++){
			$str.=$strSepa.' '.$strSepa.' '.$strSepa.' ';
		}
		return $str;
	}
}